package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlEnrol entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlEnrol
 * @author MyEclipse Persistence Tools
 */

public class MdlEnrolDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlEnrolDAO.class);
	// property constants
	public static final String ENROL = "enrol";
	public static final String STATUS = "status";
	public static final String COURSEID = "courseid";
	public static final String SORTORDER = "sortorder";
	public static final String NAME = "name";
	public static final String ENROLPERIOD = "enrolperiod";
	public static final String ENROLSTARTDATE = "enrolstartdate";
	public static final String ENROLENDDATE = "enrolenddate";
	public static final String EXPIRYNOTIFY = "expirynotify";
	public static final String EXPIRYTHRESHOLD = "expirythreshold";
	public static final String NOTIFYALL = "notifyall";
	public static final String PASSWORD = "password";
	public static final String COST = "cost";
	public static final String CURRENCY = "currency";
	public static final String ROLEID = "roleid";
	public static final String CUSTOMINT1 = "customint1";
	public static final String CUSTOMINT2 = "customint2";
	public static final String CUSTOMINT3 = "customint3";
	public static final String CUSTOMINT4 = "customint4";
	public static final String CUSTOMCHAR1 = "customchar1";
	public static final String CUSTOMCHAR2 = "customchar2";
	public static final String CUSTOMDEC1 = "customdec1";
	public static final String CUSTOMDEC2 = "customdec2";
	public static final String CUSTOMTEXT1 = "customtext1";
	public static final String CUSTOMTEXT2 = "customtext2";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEMODIFIED = "timemodified";

	public void save(MdlEnrol transientInstance) {
		log.debug("saving MdlEnrol instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlEnrol persistentInstance) {
		log.debug("deleting MdlEnrol instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlEnrol findById(java.lang.Long id) {
		log.debug("getting MdlEnrol instance with id: " + id);
		try {
			MdlEnrol instance = (MdlEnrol) getSession().get(
					"idv.loveloser.dao.MdlEnrol", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlEnrol instance) {
		log.debug("finding MdlEnrol instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlEnrol")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlEnrol instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlEnrol as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByEnrol(Object enrol) {
		return findByProperty(ENROL, enrol);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByCourseid(Object courseid) {
		return findByProperty(COURSEID, courseid);
	}

	public List findBySortorder(Object sortorder) {
		return findByProperty(SORTORDER, sortorder);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByEnrolperiod(Object enrolperiod) {
		return findByProperty(ENROLPERIOD, enrolperiod);
	}

	public List findByEnrolstartdate(Object enrolstartdate) {
		return findByProperty(ENROLSTARTDATE, enrolstartdate);
	}

	public List findByEnrolenddate(Object enrolenddate) {
		return findByProperty(ENROLENDDATE, enrolenddate);
	}

	public List findByExpirynotify(Object expirynotify) {
		return findByProperty(EXPIRYNOTIFY, expirynotify);
	}

	public List findByExpirythreshold(Object expirythreshold) {
		return findByProperty(EXPIRYTHRESHOLD, expirythreshold);
	}

	public List findByNotifyall(Object notifyall) {
		return findByProperty(NOTIFYALL, notifyall);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByCost(Object cost) {
		return findByProperty(COST, cost);
	}

	public List findByCurrency(Object currency) {
		return findByProperty(CURRENCY, currency);
	}

	public List findByRoleid(Object roleid) {
		return findByProperty(ROLEID, roleid);
	}

	public List findByCustomint1(Object customint1) {
		return findByProperty(CUSTOMINT1, customint1);
	}

	public List findByCustomint2(Object customint2) {
		return findByProperty(CUSTOMINT2, customint2);
	}

	public List findByCustomint3(Object customint3) {
		return findByProperty(CUSTOMINT3, customint3);
	}

	public List findByCustomint4(Object customint4) {
		return findByProperty(CUSTOMINT4, customint4);
	}

	public List findByCustomchar1(Object customchar1) {
		return findByProperty(CUSTOMCHAR1, customchar1);
	}

	public List findByCustomchar2(Object customchar2) {
		return findByProperty(CUSTOMCHAR2, customchar2);
	}

	public List findByCustomdec1(Object customdec1) {
		return findByProperty(CUSTOMDEC1, customdec1);
	}

	public List findByCustomdec2(Object customdec2) {
		return findByProperty(CUSTOMDEC2, customdec2);
	}

	public List findByCustomtext1(Object customtext1) {
		return findByProperty(CUSTOMTEXT1, customtext1);
	}

	public List findByCustomtext2(Object customtext2) {
		return findByProperty(CUSTOMTEXT2, customtext2);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findAll() {
		log.debug("finding all MdlEnrol instances");
		try {
			String queryString = "from MdlEnrol";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlEnrol merge(MdlEnrol detachedInstance) {
		log.debug("merging MdlEnrol instance");
		try {
			MdlEnrol result = (MdlEnrol) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlEnrol instance) {
		log.debug("attaching dirty MdlEnrol instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlEnrol instance) {
		log.debug("attaching clean MdlEnrol instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}